package com.fangtao.gps.hanlder;

import java.io.File;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;

import cn.hutool.core.io.FileUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class GpsHandler extends SimpleChannelInboundHandler<Object> {

	@Override
	protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {

		InetSocketAddress insocket = (InetSocketAddress) ctx.channel().remoteAddress();
		String clientIP = insocket.getAddress().getHostAddress();

		StringBuffer content = new StringBuffer();
		content.append(clientIP);
		content.append("------------");
		content.append(msg.toString());
		content.append("\r\n");
		FileUtil.appendString(content.toString(), new File("./origin.txt"), Charset.defaultCharset());
		
		System.out.println(content);
		
	}

}
